/*
给定一个二叉树，在树的最后一行找到最左边的值

输入:
    2
   / \
  1   3

输出:
1

输入:
        1
       / \
      2   3
     /   / \
    4   5   6
       /
      7

输出:
7

*/


/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution
{
public:
    int findBottomLeftValue(TreeNode *root)
    {
        int res;
        queue<TreeNode *> path;
        path.push(root);

        //
        while (!path.empty())
        {
            res = path.front()->val;
            int count = path.size(); //

            //
            for (int i = 0; i < count; i++)
            {
                if (path.front()->left != nullptr)
                    path.push(path.front()->left);
                if (path.front()->right != nullptr)
                    path.push(path.front()->right);
                path.pop();
            }
        }
        return res;
    }
};
